//
//  ProfileTableViewCell.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "ProfileTableViewCell.h"

@interface ProfileTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UILabel *subTitle;
@property (weak, nonatomic) IBOutlet UIImageView *moreArr;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end
@implementation ProfileTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)refreshWithItem:(TabMenuItem *)item{
    [self configBgView:item.indexFlag];
    
    self.icon.image = [UIImage imageNamed:item.icon];
    self.title.text = item.title;
    self.subTitle.text = item.subTitle;
    self.moreArr.hidden = item.isHideArr;
}


/// 设置背景图
/// @param flag -1第一个 0其他 1 最后一个
- (void)configBgView:(NSInteger)flag{
    if (flag == 0) {
        self.bgView.layer.mask = nil;
        return;
    }
    
    NSInteger type = flag > 0 ? (UIRectCornerBottomLeft | UIRectCornerBottomRight) : (UIRectCornerTopLeft | UIRectCornerTopRight);
    
    CGRect frame = self.bgView.bounds;
    frame.size.width = SCREEN_WIDTH - 30;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:type cornerRadii:CGSizeMake(8,8)];
      //创建 layer
      CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
      maskLayer.frame = frame;
      //赋值
      maskLayer.path = maskPath.CGPath;
    self.bgView.layer.mask = maskLayer;
}



@end
